package com.sky.controller.admin;


import com.sky.autoFill.AutoFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.util.List;

@RestController
@Slf4j
@Api(tags = "菜品")
@RequestMapping("/admin/dish")
public class DishController {

    @Autowired
    private DishService dishService;

    /**
     * 分页查询
     * @return
     */

    @GetMapping("/page")
    @ApiOperation("分页查询")
    public Result<PageResult> pageQuery(DishPageQueryDTO dishPageQueryDTO){
        log.info("传过来的dishPageQueryDTO为：{}",dishPageQueryDTO);
        PageResult pageResult= dishService.pageQuery(dishPageQueryDTO);
        return Result.success(pageResult);

    }

    /**
     * 增加菜品
     * @return
     */
    @PostMapping
    @ApiOperation("增加菜品")
    public Result addDish(@RequestBody DishDTO dishDTO){
        log.info("传过来的dishDTo为：{}",dishDTO);
        dishService.addDish(dishDTO);
        return Result.success();
    }

    /**
     * 根据id查菜品
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<DishVO> getById(@PathVariable Long id){
        log.info("传过来的id为：{}",id);
        DishVO dishVO=dishService.getByIdWithFlavor(id);
        return Result.success(dishVO);
    }

    @GetMapping("/list")
    @ApiOperation("添加套餐时查询")
    public Result<List<Dish>> getByIdSetmeal(@RequestParam("categoryId") Long categoryId){
        log.info("[传过来的分类id为]：{}",categoryId);
        List<Dish> dishs=dishService.getByCategoryId(categoryId);
        return Result.success(dishs);
    }



    @PutMapping
    @ApiOperation("更改菜品信息")
    public Result changeDish(@RequestBody DishDTO dishDTO){
        log.info("传过来的DishDTO为：{}",dishDTO);
        dishService.changeDish(dishDTO);
        return Result.success();
    }

    @PostMapping("/status/{status}")
    @ApiOperation("修改起售状态")
    public Result startOrStop(@PathVariable Integer status,Long id){
        log.info("传过来的status为：{}",status);
        dishService.startOrStop(status,id);
        return Result.success();
    }

    @DeleteMapping
    @ApiOperation("删除菜品")
    public Result deleteDish(@RequestParam List<Long> ids){
        log.info("菜品批量删除：{}",ids);
        dishService.deleteDishs(ids);
        return Result.success();
    }
}
